//
//  BMNavigationController.m
//  BMBlueMoonSFA
//
//  Created by mac on 16/6/5.
//  Copyright © 2016年 www.tang. All rights reserved.
//

#import "BMNavigationController.h"
#import "UIColor+BMExtension.h"
@interface BMNavigationController ()

@end

@implementation BMNavigationController
#pragma mark - 生命周期

/**
 *  当第一次使用这个类的时候调用1次
 */
+ (void)initialize
{
    // 设置UINavigationBarTheme的主
    [self setupNavigationBarTheme];
    
    // 设置UIBarButtonItem的主题
    [self setupBarButtonItemTheme];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationBar.translucent = NO;
    
    // 清空弹出手势的代理，就可以恢复弹出手势
//    self.interactivePopGestureRecognizer.delegate = nil;

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 私有方法

/**
 *  设置UINavigationBarTheme的主题
 */

+ (void)setupNavigationBarTheme{
    
    //1.导行栏全局背景色
    UINavigationBar *appearance = [UINavigationBar appearance];
    
    appearance.barTintColor = [UIColor colorWithHexString:@"1fb8ff"];
    
    //2.导行栏标题
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[UITextAttributeTextColor] = [UIColor whiteColor];
    // UITextAttributeFont  --> NSFontAttributeName(iOS7)
#warning 过期 : 并不代表不能用, 仅仅是有最新的方案可以取代它
    textAttrs[UITextAttributeFont] = [UIFont boldSystemFontOfSize:20];
    // UIOffsetZero是结构体, 只要包装成NSValue对象, 才能放进字典\数组中
    textAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
    [appearance setTitleTextAttributes:textAttrs];

    
}

/**
 *  设置UIBarButtonItem的主题
 */
+ (void)setupBarButtonItemTheme{
    
    
    
    
}

/**
 *  点击返回弹出控制器栈
 */
-(void)backClick{
    
    
    [self popViewControllerAnimated:YES];
    
}


/**
 *  能拦截所有push进来的子控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 如果现在push的不是栈底控制器(最先push进来的那个控制器)
        viewController.hidesBottomBarWhenPushed = YES;
        
        // 设置导航栏按钮
        // 返回按钮
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(0, 0, 12, 20);
        [backButton setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
        backButton.transform = CGAffineTransformMakeScale(1.2, 1.2);
        //    backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        viewController.navigationItem.leftBarButtonItem = backItem;
        [backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    }
    [super pushViewController:viewController animated:animated];
}


#pragma mark -
#pragma mark - init
#pragma mark - getters setters
#pragma mark - 系统delegate
#pragma mark - 自定义delegate
#pragma mark - 公有方法
#pragma mark - 事件响应
@end
